package com.example.controller.customer;

import com.example.dto.ShoppingCartDTO;
import com.example.entity.ShoppingCart;
import com.example.result.Result;
import com.example.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 1. @ClassDescription:
 * 2. @author: Z
 * 3. @date: 2024年03月21日 23:03
 */
@RestController
@RequestMapping("/customer/shoppingCart")
@Slf4j
@Api(tags = "C端-购物车相关接口")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车，商品信息为：{}",shoppingCartDTO);
        Result result = shoppingCartService.addShoppingCart(shoppingCartDTO);
        return result;
    }

    @GetMapping("/list/{storeId}")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> list(@PathVariable Long storeId){
        log.info("查询购物车,{}",storeId);
        List<ShoppingCart> list = shoppingCartService.showShoppingCart(storeId);
        return Result.success(list);
    }

    @DeleteMapping("/clean/{storeId}")
    @ApiOperation("清空购物车")
    public Result cleanShoppingCart(@PathVariable Long storeId){
        log.info("清空购物车,{}",storeId);
        shoppingCartService.cleanShoppingCart(storeId);
        return Result.success();
    }

    @PostMapping("/sub")
    @ApiOperation("删除购物车中一个商品")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除单个商品:{}",shoppingCartDTO);
        shoppingCartService.sub(shoppingCartDTO);
        return Result.success();
    }
}
